﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace NatNetClient
{
    /// <summary>
    /// Interaction logic for AddIpList.xaml
    /// </summary>
    public partial class AddIpList : Window
    {
        private ListBox _ipSendToList;

        public AddIpList(ListBox ipList)
        {
            InitializeComponent();
            _ipSendToList = ipList;
        }

        private void _addBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_ipTxt.Text == String.Empty || _portTxt.Text == String.Empty)
                throw new ArgumentException("Ip e port are empty");
            int port;
            if (!Int32.TryParse(_portTxt.Text, out port))
                throw new ArgumentException("Port is not a number");

            ListBoxItem item = new ListBoxItem();
            String toAdd = String.Format("{0}:{1}", _ipTxt.Text, _portTxt.Text);
            item.Content = toAdd;
            bool trovato = false;
            foreach (ListBoxItem obj in _ipSendToList.Items)
            {
                /*
                 * if (obj.Content.Equals(item.Content))
                {
                    trovato = true;
                    break;
                }
                 * */
            }
            if (!trovato)
                _ipSendToList.Items.Add(item);
        }


    }
}
